package com.live.webvideo.common.util;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class Swagger2Config {
    @Bean
    public Docket createRestApi() {
//        String auth = "d6JZlKx8l22+rX7WqmaT/Q==";
//        ParameterBuilder aParameterBuilder = new ParameterBuilder();
//                aParameterBuilder.name("token").defaultValue(auth).description("登录Token").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
//        List<Parameter> aParameters = new ArrayList<Parameter>();
//                        aParameters.add(aParameterBuilder.build());
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
//                .globalOperationParameters(aParameters)
                .select()
                //为当前包路径
                .apis(RequestHandlerSelectors.basePackage("com.live.webvideo.project.controller"))
                .paths(PathSelectors.any())
                .build();
    }
    //构建 api文档的详细信息函数
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //页面标题
                .title("图库系统接口API文档")
                //创建人
                .contact(new Contact("王东","www.baidu.com","447141101@qq.com"))
                //版本号
                .version("1.0")
                //描述
                .description("家人图库")
                .termsOfServiceUrl("*********")
                .build();
    }
}
